package cn.dapeng.tree.multi;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * 多叉树模型
 */
@Data
public class MultiTree {

    private char chars;
    private Map<Character, MultiTree> children;
    private int deep;

    public MultiTree(char chars) {
        this.chars = chars;
    }

    public MultiTree(char chars, int deep) {
        this.chars = chars;
        this.deep = deep;
    }


    public boolean isLeaf() {
        return (children == null || children.isEmpty());
    }


    public void addChild(MultiTree child) {
        if (this.children == null) {
            children = new HashMap<>();
        }

        this.children.put(child.getChars(), child);
    }

    public void removeChild(MultiTree child) {
        if (this.children != null) {
            this.children.remove(child.getChars());
        }
    }

}
